/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.helper.EncCommonHelper;
import com.minierp.model.OvBill;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class OvBillListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"OvBillList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints(10);
		font.setColor(10);
		font.setFontName("黑体");
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderBottom(1);
		cellStyle.setWrapText(true);
		cellStyle.setFillForegroundColor(22);
		cellStyle.setFillPattern(1);
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString("金额合计："
				+ model.get("costTotal").toString()));
		sheet.addMergedRegion(new Region(0, 0, 0, 8));
		r = sheet.createRow(1);
		r.createCell(0).setCellValue(new HSSFRichTextString("单号"));
		r.createCell(1).setCellValue(new HSSFRichTextString("日期"));
		r.createCell(2).setCellValue(new HSSFRichTextString("金额（元）"));
		r.createCell(3).setCellValue(new HSSFRichTextString("摘要"));
		r.createCell(4).setCellValue(new HSSFRichTextString("备注"));
		r.createCell(5).setCellValue(new HSSFRichTextString("经办人"));
		r.createCell(6).setCellValue(new HSSFRichTextString("部门"));
		r.createCell(7).setCellValue(new HSSFRichTextString("开单人"));
		r.createCell(8).setCellValue(new HSSFRichTextString("状态"));
		List list = (List) model.get("list");
		List depList = (List) model.get("depList");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

		for (int os = 0; os < list.size(); ++os) {
			OvBill b = (OvBill) list.get(os);
			r = sheet.createRow(os + 2);
			String status = "";
			if (b.getExamined().equals("Y")) {
				status = "已审核";
			} else {
				status = "未审核";
			}

			r.createCell(0).setCellValue(
					new HSSFRichTextString(b.getBillCode()));
			r.createCell(1).setCellValue(
					new HSSFRichTextString(sf.format(b.getOutDate())));
			r.createCell(2).setCellValue(b.getCost().doubleValue());
			r.createCell(3).setCellValue(
					new HSSFRichTextString(b.getDescription()));
			r.createCell(4).setCellValue(new HSSFRichTextString(b.getMark()));
			r.createCell(5).setCellValue(
					new HSSFRichTextString(b.getStafferName()));
			r.createCell(6).setCellValue(
					new HSSFRichTextString(EncCommonHelper.getSimpleObjectName(
							depList, b.getDepId())));
			r.createCell(7).setCellValue(
					new HSSFRichTextString(b.getCreaterName()));
			r.createCell(8).setCellValue(new HSSFRichTextString(status));
		}

		ServletOutputStream arg15 = response.getOutputStream();
		workbook.write(arg15);
		arg15.flush();
		arg15.close();
	}
}